﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using GraphProcessor;
using UnityEditor.Callbacks;
using System.IO;

namespace IQIGame.Onigao.GamePlay.Editors
{
	public class GraphAssetCallbacks
	{
		[MenuItem("Assets/Create/GraphProcessor/BaseGraph", false, 10)]
		public static void CreateGraphPorcessor()
		{
			var graph = ScriptableObject.CreateInstance<BaseGraph>();
			ProjectWindowUtil.CreateAsset(graph, "GraphProcessor.asset");
		}
		
		[OnOpenAsset(0)]
		public static bool OnBaseGraphOpened(int instanceID, int line)
		{
			var asset = EditorUtility.InstanceIDToObject(instanceID) as BaseGraph;
			if (asset != null && AssetDatabase.GetAssetPath(asset).Contains("Examples"))
			{
				EditorWindow.GetWindow<AllGraphWindow>().InitializeGraph(asset);
				return true;
			}
			else if (asset != null && asset is SkillEditorGraph)
			{
				EditorWindow.GetWindow<SkillEditorGraphWindow>().InitializeGraph(asset);
				return true;
			}
			else if (asset != null && asset is LevelServiceGraph)
			{
				EditorWindow.GetWindow<LevelServiceGraphWindow>().InitializeGraph(asset);
				return true;
			}
			else if (asset != null && AssetDatabase.GetAssetPath(asset).Contains("SkillConfig"))
			{
				EditorWindow.GetWindow<SkillEditorGraphWindow>().InitializeGraph(asset);
				return true;
			}
			else if (asset != null && AssetDatabase.GetAssetPath(asset).Contains("LevelService"))
			{
				// var rLevelAsset = asset as LevelServiceGraph;
				EditorWindow.GetWindow<LevelServiceGraphWindow>().InitializeGraph(asset);
				return true;
			}
			return false;
		}
	}
}
